package com.zshan.clinic.web.controller.device;


import com.zshan.clinic.common.exception.BusinessFailException;
import com.zshan.clinic.web.annotation.Permission;
import com.zshan.clinic.web.controller.AbstractController;
import com.zshan.clinic.web.entity.shanghe.ShangHeResp;
import com.zshan.clinic.web.entity.shanghe.ShangHeUploadRequest;
import com.zshan.clinic.web.service.ShangHeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * 上禾设备身高体重采集
 */
@RestController
@RequestMapping("/shanghe")
public class ShangHeController extends AbstractController {


    @Autowired
    private ShangHeService shangHeService;

    @PostMapping("/upload")
    @Permission
    public ShangHeResp upload(@Valid @RequestBody ShangHeUploadRequest shangHeUploadRequest) {
        try {
            shangHeService.upload(shangHeUploadRequest);
            return ShangHeResp.ok();
        } catch (BusinessFailException e) {
            return ShangHeResp.bad(e.getMessage());
        }catch (Exception e) {
            // 解析错误或服务器内部错误
            return ShangHeResp.fail("server error: " + e.getMessage());
        }
    }
}
